package top.opm.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jx.dao.FileInfoDao;
import top.jx.model.FileInfo;
import top.opm.dao.ServerLogDao;
import top.opm.dao.WindowsServerDao;
import top.opm.entity.ServerLog;
import top.opm.entity.WindowsServer;
import top.opm.service.WindowsServerService;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

@Service
public class WindowsServerServiceimpl implements WindowsServerService {

    private Logger log = LoggerFactory.getLogger(WindowsServerService.class);

    @Autowired
    private WindowsServerDao windowsServerDao;
    @Autowired
    private ServerLogDao serverLogDao;
    @Autowired
    private FileInfoDao fileInfoDao;



    @Override
    public String doStart(List<WindowsServer> datas) {

        WindowsServer windowsServer = datas.get(0);
        String id_rsa111 = Thread.currentThread().getContextClassLoader().getResource("id_rsa_2048-116").getPath();
        File file = new File(id_rsa111);
        String result="";
        try {
            log.info(result);
            insetLog(windowsServer, result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private void insetLog(WindowsServer windowsServer, String result) {
        ServerLog logg = new ServerLog();
        logg.setContent(result);
        logg.setTomcatName(windowsServer.getTomcatName());
        logg.setIp(windowsServer.getIp());
//        serverLogDao.save(logg);
    }

    @Override
    public String doStop(List<WindowsServer> datas) {
        String result = "";
        WindowsServer windowsServer = datas.get(0);
            windowsServer.setStatus(result);
            windowsServerDao.save(windowsServer);
        return result;
    }





    @Override
    public String executeKill(WindowsServer windowsServer) {

        String s = "";

        log.info(s);
        return s;
    }
    @Override
    public String queryStatus(WindowsServer windowsServer){
        String result = null;
        windowsServerDao.save(windowsServer);
        log.info(result);
        insetLog(windowsServer, result);
        return result;
    }

}
